﻿package com.tunan.lsj.idgenerator;

import java.text.DecimalFormat;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.tunan.common.constant.AppConfig;

/**
 * 流水号创建
 * 
 * @author czhcc
 *
 */
@Component
@Scope(value="prototype")
public class LshGenerator extends AbstractGenerator {
	
	@Autowired
	private SequenceHiLoGenerator sequenceHiLoGenerator;

	public String generate(String xzq) {
		long tmpKey = sequenceHiLoGenerator.generate(sequenceName);
		xzq= xzq.trim();
		DecimalFormat formatter = new DecimalFormat(AppConfig.YWLSH_FORMAT);
		String formmatKey = formatter.format(tmpKey);
		if (xzq == null || xzq.isEmpty()) {
			xzq = "00";
		} else {
			xzq = xzq.substring(4);
		}
		StringBuffer sb = new StringBuffer(14).append(xzq).append(formmatKey);

		System.out.println("创建的LSH=" + sb.toString());
		return sb.toString();
	}
}
